/**
 * @author LKQ
 * @date 2022/2/26 16:53
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.maximumSwap(9973);
    }
    public int maximumSwap(int num) {
        String s = "" + num;
        char[] chars = s.toCharArray();
        int n = s.length();
        for(int i = 0; i < n; i++) {
            int lo = 0 , max = 0;
            for (int j = n - 1; j > i; j--) {
                if (chars[j] - '0' > max) {
                    max = chars[j] - '0';
                    lo = j;
                }
            }
            if (lo > i && chars[i] - '0' < chars[lo] - '0') {
                char temp = chars[i];
                chars[i] = chars[lo];
                chars[lo] = temp;
                break;
            }
        }
        return Integer.parseInt(new String(chars));
    }
}
